package com.example.demonettyserver;

import com.heyi.nettylong.server.typeServer.NettyServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 */
@RestController
@RequestMapping("/netty/server")
@Slf4j
public class NettyServerController {

	@Autowired
	private NettyServer nettyServer;

	/**
	 * 发送命令socket 长链接 返回发送是否成功
	 * @param msg 命令
	 * @return
	 */
	@PostMapping("/send")
	@ResponseBody
	public Object sendmsg(String clientId, String msg) throws Exception {

		nettyServer.sendMessage(clientId, msg);
		return "ResultUtil.ok()";
	}

	/**
	 * 发送命令socket 长链接 返回发送是否成功
	 * @param msg 命令
	 * @return
	 */
	@PostMapping("/sendback")
	@ResponseBody
	public Object sendmsgback(String clientId, String msg) throws Exception {

		String m = nettyServer.sendMessageAndReturn(clientId, msg, 10);
		log.info("sendback收到数据："+ m);
		return "客户端返回："+m;
	}
}
